package com.health.demo.controller;


import com.health.demo.common.vo.Result;
import com.health.demo.entity.User;
import com.health.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 洛璃依
 * @since 2022-12-02 01:33:35
 */
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;

    //用户管理的增，删，改，查

    @PostMapping(value = "/userManager/{method}",consumes = "application/json")
    public Result<?> addDelUpdate(@PathVariable("method") String method, User user) {
        switch (method) {
            case "add":
                return userService.addUser(user);
            case "del":
                return userService.delUser(user.getUserId());
            case "update":
                return userService.updateUser(user);
            case "query":
                return userService.queryUser(user);
            default:
                return Result.error("请求地址错误！");
        }
    }
}

